<?php
/*
 * Objects identity map. This class helps to keep all objects unique in the system.
 * 
 * @author Oliver Leisalu
 * @package DomAr
 */
final class DomArIdentityMap {
	
	/**
	 * @var Array
	 */
	private static $objects = array();
	/**
	 * Add new object to identity map
	 *
	 * @param DomArDomainObject $object
	 */
	public static function add( DomArDomainObject $object ) {
		$this->objects[$object->getIdGroupName()][$object->getId()] = $object;
	}
	/**
	 * Remove object from identity map.
	 *
	 * @param DomArDomainObject $object
	 */
	public static function remove( DomArDomainObject $object ) {
		unset($this->objects[$object->getIdGroupName()][$object->getId()]);
	}
	/**
	 * Get object from identity map
	 *
	 * @param String $keyName
	 * @param Int $id
	 * @return DomArObject
	 */
	public static function get( $keyName, $id ) {
		return $this->objects[$keyName][$id];
	}
	/**
	 * Removes all objects from identity map.
	 */
	public static function flush() {
		self::$objects = array();
	}
	
}
?>